<template>
  <el-dialog
    :title="$t('buyer.details')"
    :visible.sync="dialogVisible"
    :show="show"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    width="800px"
    :before-close="handleClose"
    @open="open"
  >
    <el-form
      ref="form"
      v-loading="infoLoading"
      :model="info"
      label-width="100px"
    >
      <el-scrollbar
        ref="myScrollbar"
        :wrap-class="{ wrapClass: true }"
        class="form-scrollbar"
      >
        <div class="el-dialog-div">
          <el-form-item :label="$t('buyer.productCode')">
            <el-input
              readonly
              v-model="info.productCode"
              style="width: 120px"
            />
          </el-form-item>
          <el-form-item :label="$t('common.title')">
            <el-input readonly v-model="info.title" />
          </el-form-item>
          <el-form-item :label="$t('buyer.image')">
            <img v-if="info.image" :src="info.image" class="avatar" />
          </el-form-item>
          <el-form-item :label="$t('buyer.details')">
            <el-input type="textarea" autosize v-model="info.details" />
          </el-form-item>
          <el-form-item :label="$t('buyer.releaseTime')">
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="info.releaseTime"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item :label="$t('buyer.expireTime')">
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="info.expireTime"
            />
          </el-form-item>
          <el-form-item :label="$t('common.nation')">
            <el-input v-model="info.country" />
          </el-form-item>
          <el-form-item :label="$t('buyer.countryFlag')">
            <el-input v-model="info.countryFlag" />
          </el-form-item>
          <el-form-item :label="$t('buyer.link')">
            <el-input type="text" v-model="info.urlLink" />
          </el-form-item>
          <el-form-item :label="$t('buyer.address')">
            <el-input type="text" v-model="info.address" />
          </el-form-item>
          <el-form-item :label="$t('buyer.demand')">
            <el-input type="text" v-model="info.requireQuantity" />
          </el-form-item>
          <el-form-item :label="$t('buyer.contact')">
            <el-input type="text" v-model="info.contacts" />
          </el-form-item>
          <el-form-item :label="$t('common.email')">
            <el-input type="text" v-model="info.mailbox" />
          </el-form-item>
          <el-form-item :label="$t('buyer.wechat')">
            <el-input type="text" v-model="info.wechat" />
          </el-form-item>
          <el-form-item :label="$t('buyer.phone')">
            <el-input type="text" v-model="info.phone" />
          </el-form-item>
          <el-form-item :label="$t('buyer.categoryStubs')">
            <el-input type="text" v-model="info.categoryStubs" />
          </el-form-item>
        </div>
      </el-scrollbar>
    </el-form>
  </el-dialog>
</template>

<script>
export default {
  name: 'info',
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    rowData: {
      type: Object,
      // 对象或数组默认值必须从一个工厂函数获取
      default: function () {
        return {}
      },
    },
  },
  data() {
    return {
      uploadAction: '/api/Upload/UploadOemImg',
      dialogVisible: this.show,
      // 页面元素
      info: {},
      infoLoading: true,
    }
  },

  watch: {
    show() {
      this.dialogVisible = this.show
      this.initForm = true
    },
  },
  methods: {
    async open() {
      this.infoLoading = true
      // eslint-disable-next-line eqeqeq
      if (this.rowData.id) {
        this.info = this.rowData
      } else {
        this.info = {}
      }
      this.infoLoading = false
      console.log(this.show)
    },
    handleImageSuccess(res) {
      // eslint-disable-next-line eqeqeq
      if (res.code == 20000) {
        this.info.image = res.data
        this.infoLoading = false
      } else {
        this.$message.error(res.message)
        this.infoLoading = false
      }
    },
    handleClose(done) {
      this.$emit('update:show', false)
      this.$emit('closeAction')
    },
  },
}
</script>

<style scoped>
.el-dialog__body {
  padding: 0;
}

.form-scrollbar {
  height: 500px;
}

.el-dialog-div {
  padding: 20px 20px 0 20px;
  min-width: 400px;
}

.avatar-uploader {
  width: 178px;
  height: 178px;
  border: 1px dashed #d9d9d9;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background-color: #fbfdff;
}

.avatar-uploader:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
